package com.dragon.mmochat.dao;

import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport;

public class MmochatKbPayDao extends SimpleJdbcDaoSupport {
	// 创建kb兑换新订单
	private static final String createNewKbOrderSql = "insert into kb_pay_orders(roleid,skyid,"
			+ "kb,bigmoney,create_time) values(?, ?, ?, ?, ?)";

	public void createNewKbOrder(int roleid, long skyid, int kb, int bigmoney,
			long create_time) {
		getSimpleJdbcTemplate().update(createNewKbOrderSql, roleid, skyid, kb,
				bigmoney, create_time);
	}

	// 获取当月K币总付费额
	private static final String getMonthlyKBPayTotalValueSql = "select sum(kb) from kb_pay_orders "
			+ "where create_time >= ?";

	public int getMonthlyKBPayTotalValue(long lastMonthTime) {
		return getSimpleJdbcTemplate().queryForInt(
				getMonthlyKBPayTotalValueSql, lastMonthTime);
	}

	// 查询指定玩家的充值额
	private static final String getKBPayByIdSql = "select sum(kb) from kb_pay_orders where roleid = ?";

	public int getKBPayById(int roleId) {
		return getSimpleJdbcTemplate().queryForInt(getKBPayByIdSql, roleId);
	}

	// 查询指定玩家在指定时间内的充值额
	private static final String getKBPayByIdAndTimeSql = "select sum(kb) from kb_pay_orders "
			+ "where roleid = ? and create_time > ? and create_time < ?";

	public int getKBPayByIdAndTime(int roleId, long startTime, long endTime) {
		return getSimpleJdbcTemplate().queryForInt(getKBPayByIdAndTimeSql,
				roleId, startTime, endTime);
	}

}
